namespace Plugins.Serializer.Internal
{
    using System;
    using System.Collections;
    using System.Xml.Serialization;

    [Serializable]
    internal class PluginSerializerCache
    {
        private readonly Hashtable hashtable = new Hashtable();

        internal bool Override(IPluginRuntimeSerializerInternal key, XmlSerializer serializer)
        {
            if (key != null)
            {
                if (this.hashtable.ContainsKey(key))
                {
                    this.hashtable[key] = serializer;
                    return true;
                }
            }
            return false;
        }

        public XmlSerializer this[IPluginRuntimeSerializerInternal key]
        {
            get
            {
                XmlSerializer serializer = null;
                if (key != null)
                {
                    if (!this.hashtable.ContainsKey(key))
                    {
                        serializer = key.RuntimeSerializer;
                        this.hashtable[key] = serializer;
                        return serializer;
                    }
                    return (XmlSerializer)(hashtable[key]);
                }
                return null;
            }
        }
    }
}

